//
//  ToolView.m
//  UILibOCSample
//
//  Created by apple on 2018/3/16.
//  Copyright © 2018年 DJI. All rights reserved.
//

#import "ToolView.h"
#import "PrepareFlyVC.h"
@interface ToolView()<UIGestureRecognizerDelegate>

@end
@implementation ToolView
-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        self.backgroundColor = [UIColor whiteColor];
        self.userInteractionEnabled = YES;
        UITapGestureRecognizer *backTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(back)];
        backTap.delegate = self;
        [self addGestureRecognizer:backTap];
        
        [self initUI];
    }
    return self;
}

- (void)initUI {
    //导航栏
    UIView *naviView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kApplicationStatusBarHeight)];
    naviView.backgroundColor = [UIColor whiteColor];
    [self addSubview:naviView];
    //分割线
    UIView *segView = [[UIView alloc] initWithFrame:CGRectMake(0, naviView.frame.size.height -1, naviView.frame.size.width, 1)];
    segView.backgroundColor = segmentLineColor;
    segView.alpha = 0.8;
    [naviView addSubview:segView];
    
    //工具箱
    CGFloat titleLabW = naviView.frame.size.width / 3;
    CGFloat titleLabH = (naviView.frame.size.height - 20 ) / 2;
    CGFloat titleLabX = (naviView.frame.size.width - titleLabW) / 2;
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(titleLabX, 20, titleLabW, titleLabH)];
    titleLab.text = @"工具箱";
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.textColor = [UIColor blackColor];
    titleLab.font = [UIFont systemFontOfSize:18.f];
    [naviView addSubview:titleLab];
    
    //左上角 个人中心
    CityButton *personBtn = [[CityButton alloc] initWithFrame:CGRectMake(20, 20, naviView.frame.size.height - 30 ,naviView.frame.size.height - 30)];
    personBtn.backgroundColor = [UIColor blueColor];
    personBtn.layer.cornerRadius = (naviView.frame.size.height - 30) / 2;
    [naviView addSubview:personBtn];
    
    
    //每个按钮的宽高
    CGFloat eachBtnW = SCREEN_WIDTH / 3;
    CGFloat eachBtnH = 100;
    
    for (int i = 0; i < 3; i ++) {
        CityButton *btn = [[CityButton alloc] initWithFrame:CGRectMake(i * eachBtnW, 84, eachBtnW, eachBtnH)];
        [btn setTitleColor:[UIColor blackColor] forState:0];
        btn.tag = i;
        [btn addTarget:self action:@selector(subBtnClicked:) forControlEvents:(UIControlEventTouchUpInside)];
        if(i == 0){
            [btn setTitle:@"无人机" forState:0];
        }else if(i == 1) {
            [btn setTitle:@"我的田" forState:0];
        }else {
            [btn setTitle:@"我的圈子" forState:0];
        }
             [self addSubview:btn];
    }
    
}

/**
 *选择按钮点击
 */
- (void)subBtnClicked:(CityButton *)sender  {
    if(self.selectedBlock){
        self.selectedBlock([NSString stringWithFormat:@"%ld",(long)sender.tag]);
//        self.selectedBlock = [NSString stringWithFormat:@"%ld",(long)sender.tag];
    }
    //[self back];
}

- (void)back {
    [self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
